<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{% block title %}{% endblock %}</title>
    {% block head %}{% endblock %}
</head>
<body>
<div>
    <input id="search_value"/>
    <button id="search-btn">搜索</button>
    <a href="/">首页</a>
    <a href="/qa/publish">发布问答</a>
    {% if user %} {# 从上下文处理器中获取用户信息 #}
    <span>{{ user.username }}</span>
        <a href="/user/logout">退出</a>
    {% else %}
    <a href="/user/login">登录</a>
    {% endif %}

</div>
<div>
    {% block body %}{% endblock %}
</div>
</body>
<script>
    document.getElementById('search-btn').onclick = function () {
        var search_value = document.getElementById('search_value').value
        var url = search_value ? ('/qa/search/' + search_value) : "/"
        window.location.href = url
    }
</script>
</html>